﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML
        xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
    <META content="IE=11.0000"
          http-equiv="X-UA-Compatible">

    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <TITLE>注
        册</TITLE>
    <LINK href="/css/style.css" rel="stylesheet" type="text/css">
    <script src="/js/jquery.js"></script>


    <META name="GENERATOR" content="MSHTML 11.00.10586.420">
</HEAD>
<BODY>
<DIV class="wrap" id="header"><IMG src="/images/logo.gif"></DIV>
<DIV class="wrap" id="navbar">
    <DIV class="search"><!--
		<form method="get" action="index.html">
			<input type="text" name="keywords" class="input-text" /><input type="submit" name="submit" class="input-button" value="" />
		</form>
	-->
    </DIV>
</DIV>
<DIV class="box" id="register">
    <H2>新用户注册</H2>
    <DIV class="content">
        <FORM onsubmit="return check()" action="/addUser" method="post">
            <DL>
                <DT>用户名：</DT>
                <DD><INPUT name="vuUserName" class="input-text" id="userName" onblur="findUser(this.value,this)"
                           type="text"/><span th:text="${point}"></span></DD>
                <DT>密码：</DT>
                <DD><INPUT name="password" class="input-text" id="password" type="password"/></DD>
                <DT>确认密码：</DT>
                <DD><INPUT name="vuPassword" class="input-text" id="repass" type="password"/></DD>
                <DT></DT>
                <DD><INPUT name="submit" class="input-button" type="submit" value=""/></DD>
            </DL>
        </FORM>
        <DIV class="error"></DIV>
        <DIV class="error"></DIV>
    </DIV>
</DIV>
<DIV class="wrap" id="footer">北大青鸟 © 版权所有</DIV>
</BODY>
<SCRIPT language="javascript">
    function findUser(val, _this) {
        const this_span = $(_this).parent().find("span")
        // console.log(_this)
        $.getJSON("/findUser", {name: val}, function (data) {
            // alert(data)
            if (data == 1) {
                this_span.attr("style", "color:chartreuse")
                this_span.html("用户名可以使用")
            } else {

                this_span.attr("style", "color:red")
                this_span.html("用户名已被占用")

            }
        })
    }

    function check() {
        // alert("进入提交")
        const val = $("form").serializeArray()
        let pwd1;
        let pwd2;
        for (const valKey of val) {
            console.log(valKey)
            if (valKey.value == "") {
                alert("请将信息填写完整")
                return false;
            }
            if (valKey.name == "password") {
                pwd1 = valKey.value
            }
            if (valKey.name == "vuPassword") {
                pwd2 = valKey.value
            }
        }
        if (pwd1 != pwd2) {
            alert("密码不相同")
            return false;
        }
        return true;
    }
</SCRIPT>
</HTML>
